import cv2 as cv
import numpy as np


def big_thresh_demo(img):
    grey = cv.cvtColor(img, cv.COLOR_BGR2GRAY)
    h,w = img.shape[:2]
    cw = 123
    ch = 123
    for row in range(0,h,ch):
        for col in range(0,w,cw):
            roi = grey[row:row + ch,col:col+cw]
            std = np.std(roi)
            print(std)
            if std < 2:
                grey[row:row + ch, col:col + cw] = 255
            else:
                binary = cv.adaptiveThreshold(roi,255, cv.ADAPTIVE_THRESH_GAUSSIAN_C,cv.THRESH_BINARY,27,20)
                grey[row:row + ch,col:col+cw] = binary
    cv.imshow('binary', grey)


src = cv.imread('cards.png', 1)
big_thresh_demo(src)
cv.waitKey(0)
cv.destroyAllWindows()
